package com.cl.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.cl.entity.LiuyanEntity;
import com.cl.service.LiuyanService;
import com.cl.utils.PageUtils;
import com.cl.utils.R;

/**
 * 留言
 */
@RestController
@RequestMapping("/liuyan")
public class LiuyanController {
    @Autowired
    private LiuyanService liuyanService;
    
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = liuyanService.queryPage(params);
        return R.ok().put("page", page);
    }
    
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        LiuyanEntity liuyan = liuyanService.selectById(id);
        return R.ok().put("data", liuyan);
    }
    
    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody LiuyanEntity liuyan){
        liuyan.setLiuyanshijian(new Date());
        liuyanService.insert(liuyan);
        return R.ok();
    }
    
    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody LiuyanEntity liuyan){
        liuyanService.updateById(liuyan);
        return R.ok();
    }
    
    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        liuyanService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }

    @RequestMapping("/listByReceiver")
    public R listByReceiver(@RequestParam String jieshouren){
        List<LiuyanEntity> list = liuyanService.selectListView(jieshouren);
        return R.ok().put("list", list);
    }
} 